package cn.wolfcode.wolf2w.web.controller;



import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Region;
import cn.wolfcode.wolf2w.query.RegionQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IRegionService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.awt.*;
import java.util.List;


@Controller
@RequestMapping("region")
public class RegionController {
    @Autowired
    private IRegionService regionService;

    @Autowired
    private IDestinationService destinationService;

    /**
     * 区域管理列表显示
     * @param model
     * @param qo
     * @return
     */
    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo")RegionQuery qo){
        Page<Region> page = regionService.query(qo);
        model.addAttribute("page",page);

        return "region/list";
    }

    /**
     * 提供区域模块下拉框数据回显
     * @return
     */
    @RequestMapping("listDest")
    @ResponseBody
    public Object listDest(){

       return destinationService.list();

    }

    /**
     * 区域管理列表添加和编辑操作
     * @param region
     * @return
     */
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Region region){
        regionService.saveOrUpdate(region);
        return JsonResult.success();
    }

    /**
     * 区域管理列表删除操作
     * @param id
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public Object delete(String id){

        regionService.delete(id);
        return JsonResult.success();
    }

    /**
     * 区域管理 查看功能
     * @param rid
     * @return
     */
    @RequestMapping("/getDestByRegion")
    @ResponseBody
    public Object getDestByRegion(String rid){
        // 注入目的地的实现方法进行查询
        List<Destination> list = destinationService.queryDesByRegId(rid);

        return list;
    }

    /**
     * 区域管理热门设置
     * @param hot
     * @param id
     * @return
     */
   @RequestMapping("changeHotValue")
   @ResponseBody
    public Object changeHotValue(int hot,String id){

       regionService.changeHotValue(hot,id);

       return JsonResult.success();
    }

    /**
     * 攻略分类管理 (添加与编辑的关联目的地)
     */
    @RequestMapping("getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep){

        List<Destination> destinations = destinationService.getDestByDeep(deep);

        return destinations;
    }
}
